package com.other;

public class XiaMi2 {
    long minTimes = Integer.MAX_VALUE;

    public long GetMinCalculateCount(long sourceX, long sourceY, long targetX, long targetY) {
        bfs(sourceX, sourceY, targetX, targetY, -1);
        return minTimes == Integer.MAX_VALUE ? -1 : minTimes + 1;
    }

    private void bfs(long sourceX, long sourceY, long targetX, long targetY, long times) {
        if (sourceX == targetX && sourceY == targetY) {
            minTimes = Math.min(minTimes, times);
        }
        if (sourceX > targetX || sourceY > targetY) {
            return;
        }
        bfs(sourceX + 1, sourceY + 1, targetX, targetY, times + 1);
        bfs(sourceX * 2, sourceY * 2, targetX, targetY, times + 1);
    }

    public static void main(String[] args) {
        XiaMi2 xiaMi2 = new XiaMi2();
        System.out.println(xiaMi2.GetMinCalculateCount(10, 100, 22, 202));
    }
}
